<?php
/**
 * Created by PhpStorm.
 * User: zhangligang
 * Date: 17/5/8
 * Time: 下午1:21
 */

namespace App\Http\Controllers;

use App\Http\Models\Order;
use App\Http\Presenter\OrderPresenter;
use App\Http\Repository\OrderRepository;
use App\Http\Service\OrderService;
use Illuminate\Http\Request as HttpRequest;

class OrderController extends BaseController
{

    /**
     * @param OrderPresenter $presenter
     * @param OrderRepository $repository
     * @param OrderService $service
     */
    public function __construct(OrderPresenter $presenter, OrderRepository $repository, OrderService $service)
    {

        $this->view = ['activeFirst' => 'order', 'activeSecond' => 'index'];

        parent::__construct($presenter, $repository, $service);
    }

    /**
     * @return \Illuminate\View\View
     */
    public function index()
    {

        $orderList = Order::all(['id', 'order_sn', 'buyer_name']);

        if (count($orderList)) {

            $orderList->load(['orderGoods' => function($query){

                $query->with('goods');
            }]);
        }

        return view('order.index', array_merge(['orderList' => $orderList], $this->view));
    }

    public function set(HttpRequest $request)
    {

    }

}